-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add --env-cwd
Option To wp-env run
#49908
Add --env-cwd
Option To wp-env run
#49908
Conversation
This option allows `wp-env run` to execute from a different working directory. This is nice for relative paths
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if it'd be worthwhile to allow the input to be relative from the WordPress root to reduce noise? E.g. by default, it's resolved from /var/www/html
, and then an input of --env-cwd=wp-content/plugins/gutenberg
would work. (And if you prefix with "/", it would just pass it directly). I think we could do this with path.resolve
I agree @noahtallen, it makes more sense to use relative paths. I can't really imagine anyone ever using anything other than |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Left a suggestion for the changelog.
Co-authored-by: Noah Allen <noahtallen@gmail.com>
Thanks @noahtallen! 🚢 |
What?
By default all
wp-env run
commands are ran from/var/www/html
. This means that any relative paths used in a command are relative to this directory. This PR adds a new--env-cwd
option that changes the working directory forwp-env run
.Why?
In adding support for running PHPUnit tests to our repository, I noticed that running
wp-env run tests-wordpress /var/www/html/wp-content/plugins/woocommerce/vendor/bin/phpunit
in a script and adding a path to a test file does not work. It expects the relative path to be relative to/var/www/html
instead of thephpunit.xml
file I use.As for the name
--env-cwd
, it's important to note that any options registered bynpm
orwp-env
are consumed by their respective tools instead of being passed on.--cwd
seems likely to have been used by some tool, so, we should try and avoid conflict.I've marked this as a breaking change in case someone is using
--env-cwd
in theirwp-env run
commands. Since it's going to consume it there's the possibility it will break for someone.How?
We're using the
-w
option provided bydocker-compose run
to change the working directory of the command. This avoids any messiness with trying tocd
.Testing Instructions
npm run env -- run tests-wordpress pwd
should echo/var/www/html
.npm run env -- run tests-wordpress --env-cwd=/var pwd
should echo/var
.